package com.b511.swpu.cementbackend;

import com.b511.swpu.cementbackend.entity.*;
import com.b511.swpu.cementbackend.repository.*;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class initMasterData {

    @Autowired
    MAIN_HorizonRepository horizonRepository;

    // 层位数据
    @Test
    public void initHorizonData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:层位数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880750094");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Horizon> horizonList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 层位代码 1
                    // 系 2
                    // 统 3
                    // 组 4
                    // 段 5
                    // 地（海）域 6
                    MAIN_Horizon tmpHorizon = new MAIN_Horizon();
                    if(null != row.getCell(0)){
                        tmpHorizon.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpHorizon.setHorizonCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpHorizon.setSerial(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpHorizon.setTong(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpHorizon.setFormation(row.getCell(4).toString());
                    }
                    if(null != row.getCell(5)){
                        tmpHorizon.setSection(row.getCell(5).toString());
                    }
                    if(null != row.getCell(6)){
                        tmpHorizon.setArea(row.getCell(6).toString());
                    }
                    horizonList.add(tmpHorizon);
                }
            }
            if(0 < horizonList.size()){
                horizonRepository.saveAll(horizonList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 服务商数据
    @Autowired
    MAIN_ServicerRepository servicerRepository;

    @Test
    public void initServicerData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:服务商数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880703524");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Servicer> servicerList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 服务商编码 1
                    // 服务商名称 2
                    // 服务商代表 3
                    // 服务商电话 4
                    // 服务商地址 5
                    // 服务类别 6
                    MAIN_Servicer tmpservicer = new MAIN_Servicer();
                    if(null != row.getCell(0)){
                        tmpservicer.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpservicer.setServicerCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpservicer.setServicerName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpservicer.setServicerDelegate(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpservicer.setServicerTell(row.getCell(4).toString());
                    }
                    if(null != row.getCell(5)){
                        tmpservicer.setServicerAddress(row.getCell(5).toString());
                    }
                    if(null != row.getCell(6)){
                        tmpservicer.setCos(row.getCell(6).toString());
                    }
                    servicerList.add(tmpservicer);
                }
            }
            if(0 < servicerList.size()){
                servicerRepository.saveAll(servicerList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 国别数据
    @Autowired
    MAIN_CountryRepository countryRepository;

    @Test
    public void initCountryData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:国别数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880705086");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Country> countryList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 国别代码 1
                    // 中文名称 2
                    // 英文名称 3
                    MAIN_Country tmpCountry = new MAIN_Country();
                    if(null != row.getCell(0)){
                        tmpCountry.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpCountry.setCountryCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpCountry.setChineseName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpCountry.setEnglishName(row.getCell(3).toString());
                    }
                    countryList.add(tmpCountry);
                }
            }
            if(0 < countryList.size()){
                countryRepository.saveAll(countryList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 区块构造数据
    @Autowired
    MAIN_BlockStructureRepository blockStructureRepository;

    @Test
    public void initBlockStructureData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:区块构造数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880708012");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_BlockStructure> blockStructureList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 区块/构造编码 1
                    // 区块/构造名称 2
                    // 所属区（海）域 3
                    // 地理位置 4
                    // 所属公司标识 5
                    // 国别 6
                    // 是否陆地 7
                    MAIN_BlockStructure tmpBlockStructure = new MAIN_BlockStructure();
                    if(null != row.getCell(0)){
                        tmpBlockStructure.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpBlockStructure.setBsCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpBlockStructure.setBsName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpBlockStructure.setArea(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpBlockStructure.setLocation(row.getCell(4).toString());
                    }
                    if(null != row.getCell(5)){
                        tmpBlockStructure.setCompanyId(row.getCell(5).toString());
                    }
                    if(null != row.getCell(6)){
                        tmpBlockStructure.setCountry(row.getCell(6).toString());
                    }
                    if(null != row.getCell(7)){
                        tmpBlockStructure.setIsLand(row.getCell(7).toString());
                    }
                    blockStructureList.add(tmpBlockStructure);
                }
            }
            if(0 < blockStructureList.size()){
                blockStructureRepository.saveAll(blockStructureList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 区域/海域构造
    @Autowired
    MAIN_BlockAreaRepository blockAreaRepository;

    @Test
    public void initMainBlockAreaData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:区域海域数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880707167");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_BlockArea> blockAreaList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 区块/构造编码 1
                    // 区块/构造名称 2
                    // 所属区（海）域 3
                    MAIN_BlockArea tmpBlockArea = new MAIN_BlockArea();
                    if(null != row.getCell(0)){
                        tmpBlockArea.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpBlockArea.setBaCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpBlockArea.setBsName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpBlockArea.setCountry(row.getCell(3).toString());
                    }
                    blockAreaList.add(tmpBlockArea);
                }
            }
            if(0 < blockAreaList.size()){
                blockAreaRepository.saveAll(blockAreaList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 人员数据
    @Autowired
    MAIN_PersonRepository personRepository;

    @Test
    public void initPersonData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:人员数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880745773");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Person> personList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 员工代码 1
                    // 姓名 2
                    // 性别 3
                    // 民族 4
                    // 身份证号 5
                    // 手机号码 6
                    // 办公电话 7
                    // 邮箱 8
                    // 单位名称 9
                    // 所在部门 10
                    // 所属组织编码 11
                    MAIN_Person tmpPerson = new MAIN_Person();
                    if(null != row.getCell(0)){
                        tmpPerson.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpPerson.setCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpPerson.setName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpPerson.setSex(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpPerson.setNation(row.getCell(4).toString());
                    }
                    if(null != row.getCell(5)){
                        tmpPerson.setIdNo(row.getCell(5).toString());
                    }
                    if(null != row.getCell(6)){
                        tmpPerson.setMobilePhone(row.getCell(6).toString());
                    }
                    if(null != row.getCell(7)){
                        tmpPerson.setOfficePhone(row.getCell(7).toString());
                    }
                    if(null != row.getCell(8)){
                        tmpPerson.setEmail(row.getCell(8).toString());
                    }
                    if(null != row.getCell(9)){
                        tmpPerson.setCompanyName(row.getCell(9).toString());
                    }
                    if(null != row.getCell(10)){
                        tmpPerson.setDepartmentName(row.getCell(10).toString());
                    }
                    if(null != row.getCell(11)){
                        tmpPerson.setGroupCode(row.getCell(11).toString());
                    }
                    personList.add(tmpPerson);
                }
            }
            if(0 < personList.size()){
                personRepository.saveAll(personList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 油田数据
    @Autowired
    MAIN_OilFieldRepository oilFieldRepository;

    @Test
    public void initOilFieldData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:油田数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880709777");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_OilField> oilFieldList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 油田编码 1
                    // 油田名称 2
                    // 所属区（海）域 3
                    // 地理位置 4
                    // 经度 5
                    // 纬度 6
                    // 所属公司标识 7
                    // 国别 8
                    // 是否陆地 9
                    // 所属区块/构造 10
                    MAIN_OilField tmpOilField = new MAIN_OilField();
                    if(null != row.getCell(0)){
                        tmpOilField.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpOilField.setOilCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpOilField.setOilName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpOilField.setArea(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpOilField.setLocation(row.getCell(4).toString());
                    }
                    if(null != row.getCell(5)){
                        tmpOilField.setWellHeadLongitude(row.getCell(5).toString());
                    }
                    if(null != row.getCell(6)){
                        tmpOilField.setWellHeadLatitude(row.getCell(6).toString());
                    }
                    if(null != row.getCell(7)){
                        tmpOilField.setCompanyId(row.getCell(7).toString());
                    }
                    if(null != row.getCell(8)){
                        tmpOilField.setCountry(row.getCell(8).toString());
                    }
                    if(null != row.getCell(9)){
                        tmpOilField.setIsLand(row.getCell(9).toString());
                    }
                    if(null != row.getCell(10)){
                        tmpOilField.setBlock(row.getCell(10).toString());
                    }
                    oilFieldList.add(tmpOilField);
                }
            }
            if(0 < oilFieldList.size()){
                oilFieldRepository.saveAll(oilFieldList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 组织数据
    @Autowired
    MAIN_OrganizationRepository organizationRepository;

    @Test
    public void initOrganizationData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:组织数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880696993");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Organization> organizationList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 组织名称 1
                    // 组织编码 2
                    // 上级组织编码 3
                    // 组织层级 4
                    MAIN_Organization tmpOrganization = new MAIN_Organization();
                    if(null != row.getCell(0)){
                        tmpOrganization.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpOrganization.setName(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpOrganization.setCode(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpOrganization.setParentCode(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpOrganization.setLayer(row.getCell(4).toString());
                    }
                    organizationList.add(tmpOrganization);
                }
            }
            if(0 < organizationList.size()){
                organizationRepository.saveAll(organizationList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 钻机数据
    @Autowired
    MAIN_RigRepository rigRepository;

    @Test
    public void initRigData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:钻机数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880713927");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Rig> rigList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 钻机编码 1
                    // 名称 2
                    // 位置 3
                    // 经度 4
                    // 纬度 5
                    // 类型 6
                    MAIN_Rig tmpRig = new MAIN_Rig();
                    if(null != row.getCell(0)){
                        tmpRig.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpRig.setCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpRig.setName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpRig.setLocation(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpRig.setWellHeadLongitude(row.getCell(4).toString());
                    }
                    if(null != row.getCell(5)){
                        tmpRig.setWellHeadLatitude(row.getCell(5).toString());
                    }
                    if(null != row.getCell(6)){
                        tmpRig.setType(row.getCell(6).toString());
                    }
                    rigList.add(tmpRig);
                }
            }
            if(0 < rigList.size()){
                rigRepository.saveAll(rigList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 钻井液体系数据
    @Autowired
    MAIN_FluidSystemRepository fluidSystemRepository;

    @Test
    public void initFluidSystemData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:钻井液体系数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880731303");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_FluidSystem> fluidSystemList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 钻机编码 1
                    // 名称 2
                    // 位置 3
                    MAIN_FluidSystem tmpFluidSystem = new MAIN_FluidSystem();
                    if(null != row.getCell(0)){
                        tmpFluidSystem.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpFluidSystem.setCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpFluidSystem.setName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpFluidSystem.setType(row.getCell(3).toString());
                    }
                    fluidSystemList.add(tmpFluidSystem);
                }
            }
            if(0 < fluidSystemList.size()){
                fluidSystemRepository.saveAll(fluidSystemList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 钻具数据
    @Autowired
    MAIN_DrillToolRepository drillToolRepository;

    @Test
    public void initDrillToolData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:钻具数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880722882");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_DrillTool> drillToolList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 钻具编码 1
                    // 尺寸 2
                    // 有效长度 3
                    // 全长 4
                    // 外径 5
                    // 内径 6
                    // 容量 7
                    // 接头类型 8
                    // 标称重量 9
                    // 套管厚度 10
                    // 等级 11
                    // 螺纹类型 12
                    // 排量 13
                    // 总排量 14
                    // 接头内径 15
                    // 接头外径 16
                    // 类别 17
                    MAIN_DrillTool tmpDrillTool = new MAIN_DrillTool();
                    if(null != row.getCell(0)){
                        tmpDrillTool.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpDrillTool.setCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpDrillTool.setCaseSize(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpDrillTool.setValidLength(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpDrillTool.setFullLength(row.getCell(4).toString());
                    }
                    if(null != row.getCell(5)){
                        tmpDrillTool.setOutSize(row.getCell(5).toString());
                    }
                    if(null != row.getCell(6)){
                        tmpDrillTool.setInSize(row.getCell(6).toString());
                    }
                    if(null != row.getCell(7)){
                        tmpDrillTool.setVol(row.getCell(7).toString());
                    }
                    if(null != row.getCell(8)){
                        tmpDrillTool.setContactType(row.getCell(8).toString());
                    }
                    if(null != row.getCell(9)){
                        tmpDrillTool.setWeight(row.getCell(9).toString());
                    }
                    if(null != row.getCell(10)){
                        tmpDrillTool.setCaseThickness(row.getCell(10).toString());
                    }
                    if(null != row.getCell(11)){
                        tmpDrillTool.setGrade(row.getCell(11).toString());
                    }
                    if(null != row.getCell(12)){
                        tmpDrillTool.setThreadType(row.getCell(12).toString());
                    }
                    if(null != row.getCell(13)){
                        tmpDrillTool.setDisplacement(row.getCell(13).toString());
                    }
                    if(null != row.getCell(14)){
                        tmpDrillTool.setTotalDisplacement(row.getCell(14).toString());
                    }
                    if(null != row.getCell(15)){
                        tmpDrillTool.setContactInSize(row.getCell(15).toString());
                    }
                    if(null != row.getCell(16)){
                        tmpDrillTool.setContactOutSize(row.getCell(16).toString());
                    }
                    if(null != row.getCell(17)){
                        tmpDrillTool.setCaseCategory(row.getCell(17).toString());
                    }
                    drillToolList.add(tmpDrillTool);
                }
            }
            if(0 < drillToolList.size()){
                drillToolRepository.saveAll(drillToolList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 钻头数据
    @Autowired
    MAIN_DrillRepository drillRepository;

    @Test
    public void initDrillData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:钻头数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880722122");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Drill> drillList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 尺寸 1
                    // 类型 2
                    MAIN_Drill tmpDrill = new MAIN_Drill();
                    if(null != row.getCell(0)){
                        tmpDrill.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpDrill.setDrillSize(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpDrill.setDrillType(row.getCell(2).toString());
                    }
                    drillList.add(tmpDrill);
                }
            }
            if(0 < drillList.size()){
                drillRepository.saveAll(drillList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 作业者数据
    @Autowired
    MAIN_OperatorRepository operatorRepository;

    @Test
    public void initOperatorData(){
        // excel中的sheet
        XSSFSheet sheet;
        try {
            // 位置：resources/Data.xlsx
            File file =  ResourceUtils.getFile("classpath:钻头数据.xlsx");
            XSSFWorkbook sheets = new XSSFWorkbook(file);
            //获取sheet
            sheet = sheets.getSheet("基本信息_880722122");

            //获取行数
            int rows = sheet.getPhysicalNumberOfRows();

            // add to List
            List<MAIN_Operator> operatorList = new ArrayList<>();

            // 遍历行
            for(int i=3;i<rows && sheet.getRow(i)!=null;i++){
                XSSFRow row = sheet.getRow(i);
                // 对行数据进行处理
                if(row.getCell(0)!=null){
                    // 关联编码 0
                    // 钻机编码 1
                    // 名称 2
                    // 位置 3
                    MAIN_Operator tmpOperator = new MAIN_Operator();
                    if(null != row.getCell(0)){
                        tmpOperator.setRelationCode(row.getCell(0).toString());
                    }
                    if(null != row.getCell(1)){
                        tmpOperator.setCode(row.getCell(1).toString());
                    }
                    if(null != row.getCell(2)){
                        tmpOperator.setName(row.getCell(2).toString());
                    }
                    if(null != row.getCell(3)){
                        tmpOperator.setOperatorRepresent(row.getCell(3).toString());
                    }
                    if(null != row.getCell(4)){
                        tmpOperator.setCountry(row.getCell(4).toString());
                    }
                    operatorList.add(tmpOperator);
                }
            }
            if(0 < operatorList.size()){
                operatorRepository.saveAll(operatorList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
